import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:raze/potions/raze_constant.dart';
import 'package:raze/potions/spatial_alchemy.dart';

/// 加入圈子确认弹窗组件
class CircleJoinDialog {
  /// 显示加入圈子确认弹窗
  /// [circle] 要加入的圈子
  /// [onJoinConfirmed] 确认加入的回调
  static void revealJoinDialog({
    required dynamic circle,
    required VoidCallback onJoinConfirmed,
  }) {
    Get.dialog(
      _CircleJoinWidget(circle: circle, onJoinConfirmed: onJoinConfirmed),
      barrierDismissible: true,
    );
  }
}

/// 加入圈子确认弹窗内部组件
class _CircleJoinWidget extends StatelessWidget {
  final dynamic circle;
  final VoidCallback onJoinConfirmed;

  const _CircleJoinWidget({
    required this.circle,
    required this.onJoinConfirmed,
  });

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      elevation: 0,
      child: Container(
        width: 255.w,
        decoration: BoxDecoration(
          color: RazeConstants.yellow,
          borderRadius: BorderRadius.circular(20.r),
          border: Border.all(color: RazeConstants.black, width: 2.w),
        ),
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 23.w, vertical: 12.h),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              // 圈子名称（带黑色边框效果）
              Container(
                constraints: BoxConstraints(maxWidth: 200.w),
                child: Text(
                      'Do you want to join "${circle.title}"?',
                      textAlign: TextAlign.center,
                    )
                    .applyTypeSize(18.sp)
                    .applyTypeColor(RazeConstants.white)
                    .applyBagelFatOne(
                      weight: FontWeight.w400,
                      shadows: [
                        Shadow(
                          offset: Offset(-1.w, -1.w),
                          blurRadius: 0,
                          color: RazeConstants.black,
                        ),
                        Shadow(
                          offset: Offset(1.w, -1.w),
                          blurRadius: 0,
                          color: RazeConstants.black,
                        ),
                        Shadow(
                          offset: Offset(-1.w, 1.w),
                          blurRadius: 0,
                          color: RazeConstants.black,
                        ),
                        Shadow(
                          offset: Offset(1.w, 1.w),
                          blurRadius: 0,
                          color: RazeConstants.black,
                        ),
                        Shadow(
                          offset: Offset(0, -1.w),
                          blurRadius: 0,
                          color: RazeConstants.black,
                        ),
                        Shadow(
                          offset: Offset(0, 1.w),
                          blurRadius: 0,
                          color: RazeConstants.black,
                        ),
                        Shadow(
                          offset: Offset(-1.w, 0),
                          blurRadius: 0,
                          color: RazeConstants.black,
                        ),
                        Shadow(
                          offset: Offset(1.w, 0),
                          blurRadius: 0,
                          color: RazeConstants.black,
                        ),
                      ],
                    ),
              ),
              24.h.boxHeight,

              // 按钮
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  // 取消按钮
                  Expanded(
                    child: Container(
                          height: 38.h,
                          decoration: BoxDecoration(
                            color: RazeConstants.white,
                            borderRadius: BorderRadius.circular(12.r),
                            border: Border.all(
                              color: RazeConstants.black,
                              width: 1.w,
                            ),
                          ),
                          alignment: Alignment.center,
                          child: Text('Cancel')
                              .applyTypeSize(14.sp)
                              .applyTypeColor(RazeConstants.black)
                              .applyNotoSans(weight: FontWeight.w600),
                        )
                        .withRightBottomShadow(thickness: 1)
                        .withTouchResonance(onTap: () => Get.back()),
                  ),
                  16.w.boxWidth,

                  // 确认按钮
                  Expanded(
                    child: Container(
                          height: 38.h,
                          decoration: BoxDecoration(
                            color: RazeConstants.yellow,
                            borderRadius: BorderRadius.circular(12.r),
                            border: Border.all(
                              color: RazeConstants.black,
                              width: 1.w,
                            ),
                          ),
                          alignment: Alignment.center,
                          child: Text('Confirm')
                              .applyTypeSize(14.sp)
                              .applyTypeColor(RazeConstants.black)
                              .applyNotoSans(weight: FontWeight.w600),
                        )
                        .withRightBottomShadow(thickness: 1)
                        .withTouchResonance(
                          onTap: () {
                            Get.back();
                            onJoinConfirmed();
                          },
                        ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
